package com.ebocy.hammer.core.db;

import java.util.List;
import java.util.Map;

import com.ebocy.hammer.core.db.mongo.backend.IndexChecker;
import com.ebocy.hammer.core.db.mongo.mapper.Operator;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

/**
 * normal database  action
 *2012-3-22@author yangshaobo
 * @param <T>
 */
public interface IDao<T extends IEntity> {
	 public IEntity insert(IEntity obj);
	 public void insert(List<IEntity> list);
	 public void save(IEntity obj);
	 public void delete(IEntity obj);

	 public List<T> find(String key, Object value);

	 public T findOne(String id);

	 public T findOne(String key, Object value);

	 public List<T> findAll();
	 /**
     * Remove by id.
     * @param id
     */
    public void delete(String id);
    /**
     * Remove by array of id.
     * @param ids
     */
    public void delete(String... ids);
    /**
     * Remove entity by condition.
     * @param key the condition field
     * @param value the condition value
     */
    public void delete(String key, Object value);
    /**
     * Update an entity, with new key/value pairs.
     * @param obj the entity needs to be updated
     * @param values the new key/value pairs
     */
    public void update(IEntity obj, Map values);
    /**
     * Update an entity, with new key/value pairs.
     * @param id the entity's id
     * @param values the new key/value pairs
     */
    public void update(String id, Map values);
    /**
     * Count all entity.
     * @return
     */
    public long count();
    /**
     * Count by condition.
     * @param key the condition field
     * @param value the condition value
     * @return
     */
    public long count(String key, Object value);
    public void set(IEntity obj, String key, Object value);

    /**
     * Update a field's value of an entity.
     * @param id the entity's id
     * @param key the field's name
     * @param value the field's new value
     */
    public void set(String id, String key, Object value);
    /**
     * add properties,add by lichunmei
     * @param obj
     * @param key
     * @param value
     */
    public void inc(IEntity obj, String key, Object value);
    /**
     * del row , add by lichunmei
     * @param entity
     * @param key
     */
    public void unset(IEntity entity, String key);
}